<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>退换车标签维护</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<form id="searchBar">
	 <div class="fieldBox col_33">
         <div class="field">
              <lable>是否退换车业务</lable>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
              <select name="tagTypeCd" id="tagTypeCd" style="width:138.4px;">
                   <option value="  " selected="selected">--请选择--</option>
                   <c:forEach items="${tagTypeCdList}" var="opt">
                   <option value="${opt.key}">${opt.value}</option>
                   </c:forEach>
              </select>
          </div>
     </div>
     <div class="fieldBox col_33" style="margin-top:20px;" id="prePaySchNoFlag">
          <div class="field">
                <lable>关联的其它支付表</lable>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;
                <input name="prePaySchNo" id="prePaySchNo" type="text" class="ui-textbox" value="">
                <div style="margin-top:10px;margin-left:220px;">
                    <p id="changeCar" style="color:red;">*换车业务，仅车价不一致时需填写关联的支付表</p>
                    <p id="changePerson" style="color:red;">*换承租人业务必须填写关联的其他支付表</p>
                </div>
          </div>
     </div>
     <div class="btnsBox" style="margin-top:20px;">
          <span id="commitBtn" onclick="commitBtn();" class="sq-button sq-button-round" style="margin-left:100px;">提交</span>
          <span id="resetBtn" onclick="resetBtn();" class="sq-button sq-button-round" style="margin-left:100px;">重置</span>
     </div>
</form>
</div>

<script type="text/javascript">
    var paySchNo = '${paySchNo}';
    var prePaySchNo = '${prePaySchNo}';
    var tagFlag = '${tagFlag}';
    var tagTypeCd = '${tagTypeCd}';
    //标记名称 reset-重置退换车标签,add-新增退换车标签
    var tagName = '${tagName}';

    $(function () {
        $("#tagTypeCd").change(function () {
             var tagTypeCdVal = $(this).val();
             if(tagTypeCdVal == "0" || tagTypeCdVal == "1" || tagTypeCdVal =="  "){
                 //隐藏关联的其它支付表输入框
                 $("#prePaySchNoFlag").hide();
             }
             if(tagTypeCdVal == "2"){
                 $("#prePaySchNoFlag").show();
                 $("#changeCar").show();
                 $("#changePerson").hide();
             }
             if(tagTypeCdVal == "3"){
                 $("#prePaySchNoFlag").show();
                 $("#changeCar").hide();
                 $("#changePerson").show();
             }
        });
        //新增退换车标签
        if("add" == tagName){
            //隐藏重置按钮
            $("#resetBtn").hide();
            //隐藏关联的其它支付表输入框
            $("#prePaySchNoFlag").hide();
        }
        //重置退换车标签
        if("reset" == tagName){
            //隐藏提交按钮
            $("#commitBtn").hide();
            if(tagFlag != "0"){
                var selectTagTypeCd = document.getElementById('tagTypeCd');
                selectTagTypeCd.value = tagTypeCd;
                selectTagTypeCd.setAttribute("disabled","disabled");
                if(tagTypeCd == "0" || tagTypeCd == "1"){
                    //隐藏关联的其它支付表输入框
                    $("#prePaySchNoFlag").hide();
                }
                if(tagTypeCd == "2"){
                    $("#prePaySchNoFlag").show();
                    $("#changeCar").show();
                    $("#changePerson").hide();
                }
                if(tagTypeCd == "3"){
                    $("#prePaySchNoFlag").show();
                    $("#changeCar").hide();
                    $("#changePerson").show();
                }
                var inputPrePaySchNo = document.getElementById('prePaySchNo');
                inputPrePaySchNo.value = prePaySchNo;
                inputPrePaySchNo.disabled = true;
            }
        }
    });

   function resetBtn(){
       if (tagTypeCd && tagTypeCd == "1") {
           $.ligerDialog.alert("退车已完成，请重新立项!");
           return;
       }
       if (tagTypeCd && tagTypeCd == "2") {
           $.ligerDialog.alert("换车已完成，不可重置是否退换车业务标记!");
           return;
       }
        var data = {};
        data["paySchNo"] =paySchNo;
        data["prePaySchNo"] =prePaySchNo;
        data["tagTypeCd"] =tagTypeCd;
        data["tagName"] =tagName;
        var confirmInfo = "操作后该支付表和其关联支付表都将被重置，请确认!";
   		$.ligerDialog.confirm(confirmInfo, function (flag) {
   			if(flag == false)return;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:data,
   				url: '<%=path%>/project/prjprdpayschm/siteTagTypeCd.do',
   				success:function(msg){
   					 if(msg.success == 1){
   						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
   					 }else{
   						 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
   					 }
   				}
   			});
   		});
   	}

	function commitBtn(){
		    var tagTypeCd = $("#tagTypeCd option:selected").val();
		    var prePaySchNo = $("#prePaySchNo").val();
		    if (tagTypeCd && tagTypeCd == "1") {
                $.ligerDialog.alert("请在项目管理-变更管理申请退车流程!");
                return;
            }
        if (tagTypeCd && tagTypeCd == "2") {
            $.ligerDialog.alert("请在项目管理-变更管理申请换车流程!");
            return;
        }
		    var data = {};
		    data["paySchNo"] =paySchNo;
		    data["prePaySchNo"] =prePaySchNo;
		    data["tagTypeCd"] =tagTypeCd;
		    data["tagName"] =tagName;
		    var url = '<%=path%>/project/prjprdpayschm/siteTagTypeCd.do';
		    $.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: url,
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					 wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:"标签添加成功！", SQ_type: "success"});
                         //closeWindows();
					 }else{
					     $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					 }
				},error:function (XMLHttpRequest, textStatus, errorThrown) {
                     $.ligerDialog.SQalert({content: "网络错误，请稍后重试!",SQ_type: "error"});
                }
			});
	}

	function closeWindows() {
        var userAgent = navigator.userAgent;
        if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
            //直接调用JQUERY close方法关闭
            close();
        } else {
            window.opener = null;
            window.open("", "_self");
            window.close();
        }
    };

</script>
</body>
</html>
